#!/bin/awk -f
#-------------------------------------------------------------------------------
#	file conv.awk
#
#	brief
#	Convert event log data to a human readable form.
#
#	Input Record format:
#	$1 - event log byte
#	All other fields are ignored
#
#	Output Record format:
#	$1 - log id
#	$2 - Human readable version of log ID
#
#	$Id: conv.awk 350 2015-02-26 18:25:37Z ac.verbeck@gmail.com $
#-------------------------------------------------------------------------------
#	INT_I2C_S1			= 0x11,
#	INT_I2C_S2			= 0x12,
#	INT_I2C_DATA		= 0x13,
#	INT_I2C_DONE		= 0x14,
#	INT_DMA_DONE		= 0x15
#
#	I2C_CMD_ENABLE		= 0x20,
#	I2C_CMD_GET_STATE	= 0x21,
#	I2C_CMD_RESET		= 0x22,
#	I2C_CMD_GET_LEN		= 0x23,
#	I2C_CMD_GET_DATA	= 0x24,
#	I2C_CMD_WHO_AM_I	= 0x25,
#
#	EV_QUEUE_BUFFER		= 0x30,
#	EV_DMA_CFG			= 0x31,
#	EV_CMD_PROC			= 0x32,
#	EV_END_LOG			= 0x33,
#-------------------------------------------------------------------------------

#
#	Convert data from log format to something more readable
#
NF == 0 {
	next
}

#
#	Interrupts
#
$1 == 11 {
	printf("Log: %02d Interrupt: I2C_Start\n", $1);
	next
}
$1 == 12 {
	printf("Log: %02d Interrupt: I2C_Restart\n", $1);
	next
}
$1 == 13 {
	printf("Log: %02d Interrupt: I2C_Data\n", $1);
	next
}
$1 == 14 {
	printf("Log: %02d Interrupt: I2C_Done\n", $1);
	next
}
$1 == 15 {
	printf("Log: %02d Interrupt: DMA_Done\n", $1);
	next
}

#
#	I2C commands
#
$1 == 20 {
	printf("Log: %02d I2C: enable sensor\n", $1);
	next
}
$1 == 21 {
	printf("Log: %02d I2C: get sensor state\n", $1);
	next
}
$1 == 22 {
	printf("Log: %02d I2C: reset\n", $1);
	next
}
$1 == 23 {
	printf("Log: %02d I2C: get data length\n", $1);
	next
}
$1 == 24 {
	printf("Log: %02d I2C: get data\n", $1);
	next
}
$1 == 25 {
	printf("Log: %02d I2C: who am i\n", $1);
	next
}


#
#	Events
#
$1 == 30 {
	printf("Log: %02d Event: EV_QUEUE_BUFFER\n", $1);
	next
}
$1 == 31 {
	printf("Log: %02d Event: EV_DMA_CFG\n", $1);
	next
}
$1 == 32 {
	printf("Log: %02d Event: EV_CMD_PROC\n", $1);
	next
}
$1 == 33 {
	printf("Log: %02d Event: EV_END_LOG\n", $1);
	next
}

{
	printf("Log: %02d Unknown Event\n", $1);
	exit(1)
}
